<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Find Missing Rosetta Records</title>
</head>

<!--- Find stragglers.  People who's Compnay in AD was not listed and therefore not found previously--->
<cfldap action="QUERY"
	name="qryEmployeesFromLDAP"
	SCOPE="subtree"
	start="ou=SCFUsers,dc=SouthcentralFoundation,dc=com"
	filter="(&(objectclass=user))"
	server="10.100.1.9"
	attributes="objectclass,company,dn,givenname,sn,displayName,mail,telephonenumber,sAMAccountName, mailNickname, useraccountcontrol"
	sort="displayName"
	SORTCONTROL="nocase"
	username="scf\Userlist"
	password="DefinedMan" />


<cfquery name="qryGetAccountsWithOutSCFCompany" dbtype="query">
	SELECT objectclass, company, givenname, sn, displayname, sAMAccountName, mailNickName
	FROM qryEmployeesFromLDAP
	WHERE company not in ('SCF', 'Southcentral Foundation')
	order by Company, sn, givenname
</cfquery>
<cfdump var="#qryGetAccountsWithOutSCFCompany#">

<!---cfldap action="QUERY"
	name="qryEmployeesFromLDAP"
	SCOPE="subtree"
	start="dc=SouthcentralFoundation,dc=com"
	filter="(&(|(objectclass=contact)(objectclass=user))(!(title=*Non-Employee*))(&(title=*))(|(company=ANMC)(company=SCF)(company=Southcentral Foundation)))"
	server="10.100.1.9"
	attributes="objectclass,company,dn,givenname,sn,displayName,mail,telephonenumber,sAMAccountName, mailNickname, useraccountcontrol"
	sort="displayName"
	SORTCONTROL="nocase"
	username="scf\Userlist"
	password="DefinedMan" />




<cfquery name="qryGetSCFLDAP" dbtype="query">
	SELECT *
	FROM qryEmployeesFromLDAP
	WHERE company in ('SCF', 'Southcentral Foundation')
	order by Company, sn, givenname
</cfquery>

<cfloop query="qryGetSCFLDAP">
	<cfif FindNoCase("TempUsersOU",dn) EQ 0>
		<!---Add to Temp AD Import Table --->
		<cfif isnumeric(useraccountcontrol)>
			<cfset intControl = useraccountcontrol>
		<cfelse>
			<cfset intControl = 0>
		</cfif>
		<cfquery name="qryInsertIntoADImport" datasource="RosettaStone">
			Insert Into TempADImport (Company, FirstName, LastName, Email, UserID, Alias, AccountControl)
     			VALUES ('#Company#', '#givenname#', '#sn#', '#mail#', '#sAMAccountName#', '#mailNickname#', #intControl#)
		</cfquery>
		<cfoutput>#Company#, #sn#, #givenname#, #mail#, #sAMAccountName#, #dn#<BR /></cfoutput>
	</cfif> 
</cfloop>

<cfquery name="test" datasource="RosettaStone">
	Select * from TempADImport
</cfquery>
<cfdump var="#test#"--->
<body>
</body>
</html>
